package chongwo.cn.mediaplayerproject;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Scroller;

public class FirstView extends View {
    private Scroller scroller;

    public FirstView(Context context, AttributeSet attrs) {
        super(context, attrs);
        scroller = new Scroller(context);
    }

    @Override
    public void computeScroll() {
        super.computeScroll();
        Log.i("json", "computeScroll:" + scroller.computeScrollOffset());
        if (scroller.computeScrollOffset()) {
            ((View) getParent()).scrollTo(scroller.getCurrX(), scroller.getCurrY());
            invalidate();
            Log.i("json", "computeScroll");
        }
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Log.i("json", "onDraw");
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.i("json", event.getAction() + ":" + MotionEvent.ACTION_UP);
        if(event.getAction() == MotionEvent.ACTION_UP) {
        }
        View view = (View) getParent();
        scroller.startScroll(view.getScrollX(), view.getScrollY(), -view.getScrollX(), -view.getScrollY());
        invalidate();
        return super.onTouchEvent(event);
    }
}
